<?php

namespace app\index\controller;

use app\home\model\Course;
use app\home\model\Apply;

class  Courses2 extends Base
{
    public function index()
    {
      $res = Course::order("id","asc")->select();
      $resArr = collection($res)->toArray();
      $applys = Apply::field("major,count(*) as c")->group("major")->select();
      $arr = [];
      foreach($applys as $val){
        $arr[$val['major']] = $val['c'];
      }

      foreach($resArr as $key=>$val){
        $resArr[$key]['apply_number'] = array_key_exists($val['name'],$arr) ? $arr[$val['name']] : 0;
        $resArr[$key]['name'] = $val['name'];
      }
      return json($resArr);
    }
    public function first()
    {
      $res = Course::order("id","asc")->find();
      return $res["name"];
    }

}
